import asyncio
import websockets

# 定义接收消息处理函数
async def receive(websocket, path):
    async for message in websocket:
        print(f"收到消息：{message}")
        await websocket.send(f"收到消息：{message}")

# 启动WebSocket服务器
async def server():
    async with websockets.serve(receive, "0.0.0.0", 8765):
        print("WebSocket服务器已启动...")
        await asyncio.Future()  # 让WebSocket服务器一直运行

# 启动WebSocket服务器
asyncio.run(server())